
# coding:utf-8

import random

from lib import flux, al
from lib.fluxext import singleton


@singleton
class AISys(object):
    #ours = set()
    enemy = set()
    count = 0

    def __init__(self):
        choices = (al.KEY_LEFT, al.KEY_RIGHT, al.KEY_UP, al.KEY_DOWN)

        def OnFire():
            for i in self.enemy:
                i.Attack()
                if self.count % 3 == 0:
                    i.Move(random.choice(choices))

            self.count += 1

        self.t = flux.Timer(1.5)
        self.t.OnFire = OnFire
        self.t.Start()

    def AddEnemy(self, e):
        self.enemy.add(e)

    def RmEnemy(self, e):
        self.enemy.remove(e)
